package com.example.pinkcat.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.pinkcat.R;
import com.example.pinkcat.activity.adapter.VIP_recyleview_adapter;
import com.example.pinkcat.activity.api.getData.GetData;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.util.Objects;

public class PinkCatVip extends AppCompatActivity {
    Context context=this;

    RecyclerView recyclerView;//会员套餐列表


    ImageView imageView_vip;//收款码
    TextView select_money;//当前套餐钱

    View vip_back;//vip背景
    TextView isVip;//是不是vip
    TextView startvip;//是不是vip
    TextView endvip;//是不是vip
    TextView name;//是不是vip
    RoundedImageView head;//头像
    View getvipbnt;//提交vip

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_pink_cat_vip);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏

        recyclerView=findViewById(R.id.recycle_vip);
        vip_back=findViewById(R.id.head_layoutssss);
        isVip=findViewById(R.id.viptext_is);
        imageView_vip=findViewById(R.id.vip_img);
        select_money=findViewById(R.id.select_money);
        head=findViewById(R.id.user_head);
        startvip=findViewById(R.id.start_vip);
        endvip=findViewById(R.id.end_vip);
        name=findViewById(R.id.vipname);
        getvipbnt=findViewById(R.id.getvipbtn);

        recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL,false));
        VIP_recyleview_adapter vip_recyleview_adapter=new VIP_recyleview_adapter(context,4,select_money,imageView_vip);
        recyclerView.setAdapter(vip_recyleview_adapter);


        if (userStaticMsg.vip==0){
            vip_back.setBackground(getResources().getDrawable(R.drawable.backgroud_cycle_grey_whit));
            isVip.setText("你目前不是大会员");
        }
        else if (userStaticMsg.vip==1){
            vip_back.setBackground(getResources().getDrawable(R.drawable.backgroud_cycle_pink_whit));
            isVip.setText("PinkCat大会员");
        }
        //返回键监听
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //提交vip申请
        getvipbnt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                findViewById(R.id.progressBar_wait).setVisibility(View.VISIBLE);
                if (select_money.getText().toString().equals("1 元")){
                    if (GetData.getvip(context,"1"))
                        onBackPressed();
                }
                else if (select_money.getText().toString().equals("20 元")){
                    if (GetData.getvip(context,"2"))
                        onBackPressed();
                }
                else if (select_money.getText().toString().equals("60 元")){
                    if (GetData.getvip(context,"3"))
                        onBackPressed();
                }
                else if (select_money.getText().toString().equals("999 元")){
                    if (GetData.getvip(context,"4"))
                        onBackPressed();
                }
                findViewById(R.id.progressBar_wait).setVisibility(View.INVISIBLE);
            }
        });
        if (!GetData.getvipinfo(context,head,name,isVip,startvip,endvip,vip_back)){
            System.out.println("erro");
        }
    }
}